package mymyoux.utils
{
	public class Validators
	{
		static public const EMAIL:String="EMAIL";
		static public const URL:String="URL";
		public function Validators()
		{
		}
		static public function test(source:String,type:String):Boolean
		{
			var r:RegExp;
			switch(type)
			{
				case EMAIL:
					r=new RegExp("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$");
					return r.test(source);
				break;
				case URL:
					r=new RegExp("^(((mailto\:|(news|(ht|f)tp(s?))\://){1}[^ ]+))|(www\.[^ ]+)$","i");
					return r.test(source);
				break;
				default:
					return false;
			}
		}
		static public function contains(source:String,type:String):Boolean
		{
			var r:RegExp;
			switch(type)
			{
				case EMAIL:
					r=new RegExp("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}");
					return r.test(source);
				break;
				case URL:
					r=new RegExp("(((mailto\:|(news|(ht|f)tp(s?))\://){1}[^ ].+))|(www\.[^ ]+)","i");
					return r.test(source);
				break;
				default:
					return false;
			}
		}
	}
}